<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;

class CreateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
//            "merchant_id" => "string|gt:0|bail",
            "type" => "required|integer|in:0,1,2|bail",
            "source_id" => "required_if:type,1|integer|gte:0|bail",
            "receive_number" => "required|integer|gt:0|bail",
            "max_number" =>  "required|integer|gt:0|bail",
            "discount_type" => "required|integer|in:0,1,2|bail",
            "conditional_amount" => "required|numeric|gte:0|bail",
            "discount_amount" => "required|numeric|gt:0|bail",
            "period_validity" => "required|integer|in:0,1|bail",
            "expiration_date" => "required_if:period_validity,1|integer|gt:0|bail",
            "usage_rules" => "required|bail",
            "status" => "integer|in:0,1"
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [];
    }

    /**
     * Get custom attributes for validator errors.
     */
    public function attributes(): array
    {
        return [
            "merchant_id" => "商户ID",
            "type" => "类型",
            "source_id" => "资源ID",
            "receive_number" => "单用户最大领取数量",
            "max_number" => "总数量",
            "discount_type" => "优惠类型",
            "conditional_amount" => "满足优惠条件金额",
            "discount_amount" => "优惠额度",
            "period_validity" => "有效期类型",
            "expiration_date" => "有效时间",
            "usage_rules" => "使用规则",
            "status" => "状态"
        ];
    }
}
